package com.ibeetl.admin.console.web;

import com.ibeetl.admin.console.service.CoreDataService;
import com.ibeetl.admin.core.web.JsonResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
public class CoreDataController {

    private final Log log = LogFactory.getLog(this.getClass());
    private static final String MODEL = "/admin/data";

    @Autowired
    CoreDataService coreDataService;

    @RequestMapping(value = MODEL + "/yesterday", method = RequestMethod.GET)
    @ResponseBody
    public JsonResult<HashMap> getYesterdayOrderData() {
        return JsonResult.success(coreDataService.queryOrderDataByDate(1));
    }

    @RequestMapping(value = MODEL + "/lastweek", method = RequestMethod.GET)
    @ResponseBody
    public JsonResult<HashMap> getLastWeekOrderData() {
        return JsonResult.success(coreDataService.queryOrderDataByDate(7));
    }

    @RequestMapping(value = MODEL + "/lastmonth", method = RequestMethod.GET)
    @ResponseBody
    public JsonResult<HashMap> getLastMonthOrderData() {
        return JsonResult.success(coreDataService.queryOrderDataByDate(30));
    }


    @RequestMapping(value = MODEL + "/1", method = RequestMethod.GET)
    @ResponseBody
    public JsonResult<HashMap> getLastDaySaleData() {
        return JsonResult.success(coreDataService.querySaleRateByDate(1));
    }

    @RequestMapping(value = MODEL + "/7", method = RequestMethod.GET)
    @ResponseBody
    public JsonResult<HashMap> getLastWeekSaleData() {
        return JsonResult.success(coreDataService.querySaleRateByDate(7));
    }

    @RequestMapping(value = MODEL + "/30", method = RequestMethod.GET)
    @ResponseBody
    public JsonResult<HashMap> getLastMonthSaleData() {
        return JsonResult.success(coreDataService.querySaleRateByDate(30));
    }


}
